import json
import os
from typing import Dict, Any
from PyQt5.QtCore import QSettings

class ConfigManager:
    """配置管理类，安全地存储应用配置"""
    
    def __init__(self, app_name: str = "SecureNoteApp", org_name: str = "SecureNote"):
        self.settings = QSettings(org_name, app_name)
        
    def get_user_config(self, username: str) -> Dict[str, Any]:
        """获取用户配置"""
        users = self.settings.value("users", {})
        return users.get(username, {})
        
    def set_user_config(self, username: str, config: Dict[str, Any]) -> bool:
        """设置用户配置"""
        try:
            users = self.settings.value("users", {})
            users[username] = config
            self.settings.setValue("users", users)
            return True
        except Exception:
            return False
            
    def remove_user_config(self, username: str) -> bool:
        """移除用户配置"""
        try:
            users = self.settings.value("users", {})
            if username in users:
                del users[username]
                self.settings.setValue("users", users)
            return True
        except Exception:
            return False